package com.libgdxbar.pvzlikegame.entities;

import com.badlogic.gdx.ai.fsm.DefaultStateMachine;
import com.badlogic.gdx.ai.fsm.StateMachine;
import com.libgdxbar.pvzlikegame.systems.state.IEntityState;
import org.libgdxbar.projects.interfaces.IState;

public class StateEntity extends Entity implements IState {

	private StateMachine<IState, IEntityState> stateMachine = new DefaultStateMachine<>();

	@Override
	public void changeState(IEntityState state) {
		stateMachine.changeState(state);
	}

	@Override
	public IEntityState getState() {
		return stateMachine.getCurrentState();
	}

	@Override
	public void changeToPreviousState() {
		IEntityState previousState = stateMachine.getPreviousState();
		stateMachine.changeState(previousState);
	}

	@Override
	public void run(float delta) {
		stateMachine.update();
	}
}
